<template>
  <div class="container" :class="{ checked: status }">
    <div class="item-check">
      <input type="checkbox" v-model="status" name="" id="" @change="sendchecked" />
    </div>
    <div class="item-form">
      <img :src="itemImg" alt="" />
      <div class="p-name">
        {{ itemname }}
      </div>
      <div class="cell-price">
        <span class="p-price-cont">￥{{ price }}</span>
      </div>
      <div class="p-quantity">
        <!-- <button @click="sub">-</button>
        <input type="text" class="p-input" v-model="count" />
        <button @click="add">+</button> -->
        <el-input-number v-model="num" :min="1" size="mini" @change="sendData"></el-input-number>
      </div>
      <div class="p-sum">
        <strong>￥{{ total }}</strong>
      </div>
      <div class="p-action">
        <a href="javascript:;" @click="deleteItem">删除</a>
        <a href="javascript:;">移入关注</a>
      </div>
    </div>
  </div>
</template>

<script>
import imgurl from '@/assets/image/shopcaritem.jpg'
export default {
  props: {
    price: {
      type: Number,
      required: true
    },
    id: {
      type: String,
      required: true
    },
    itemname: {
      type: String,
      required: true
    },
    quantity: {
      type: Number,
      required: true
    },
    img: {
      type: String,
      required: true
    },
    seleted: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      imgurl,
      num: this.quantity,
      itemImg: '/api' + this.img,
      status: this.seleted
    }
  },
  methods: {
    sendData() {
      this.$emit('syncData', {
        quantity: this.num,
        total: Number((this.num * this.price).toFixed(2)),
        id: this.id
      })
    },
    sendchecked() {
      this.$emit('sendchecked', { id: this.id, checked: this.status })
    },
    deleteItem() {
      this.$emit('deleteItem', this.id)
    }
  },
  watch: {
    seleted: function(val) {
      this.status = val
    }
  },
  computed: {
    total() {
      return (this.num * this.price).toFixed(2)
    }
  }
}
</script>

<style lang="less" scoped>
.checked {
  background-color: #fff8e1;
}
.container {
  margin: 5px auto;
  width: 986px;
  height: 119px;
  border: 1px solid #f1f1f1;
  user-select: none;
  .item-check {
    float: left;
    width: 40px;
    height: 70px;
    line-height: 70px;
    text-align: center;
  }
  .item-form {
    width: 940px;
    height: 107px;
    float: right;
    font-size: 12px;
    color: #434343;
    img {
      margin-top: 20px;
      margin-left: 10px;
      border: 1px solid rgba(165, 152, 152, 0.4);
      float: left;
      width: 80px;
      height: 80px;
    }
    .p-name {
      float: left;
      margin-top: 20px;
      margin-left: 10px;
      word-wrap: break-word;
      word-break: break-all;
      height: 40px;
      width: 208px;
      line-height: 20px;
      overflow: hidden;
    }
    .cell-price {
      float: left;
      margin-top: 20px;
      margin-left: 145px;
    }
    .p-quantity {
      float: left;
      margin-top: 20px;
      margin-left: 30px;
      height: 15px;
      .p-input {
        outline: none;
        width: 50px;
        text-align: right;
      }
    }
    .p-sum {
      float: left;
      margin-top: 20px;
      margin-left: 70px;
    }
    .p-action {
      float: left;
      margin-top: 20px;
      margin-left: 70px;

      a {
        text-decoration: none;
        display: block;
        color: #434343;
      }
      a:hover {
        color: red;
      }
    }
  }
}
</style>
